export class DomUtil {

  public static createOption(label: string, value: string, attributes: ElementAttribute[]): HTMLOptionElement {

    const result = document.createElement("option");
    result.value = value;
    result.innerText = label;
    this.addAttributes(result, attributes);
    return result;
  }

  public static createSelect(name: string, options: HTMLOptionElement[], attributes: ElementAttribute[]): HTMLSelectElement {
    const result = document.createElement("select");
    for (let i = 0; i < options.length; i++) {
      result.add(options[i]);
    }
    this.addAttributes(result, attributes);
    return result;

  }

  private static addAttributes(node: Element, attributes: ElementAttribute[]): void {
    for (let i = 0; i < attributes.length; i++) {
      node.setAttribute(attributes[i].attName, attributes[i].attValue);
    }
  }
}

export class ElementAttribute {
  attName: string;
  attValue: string;
}

